<?php

/**
 * This is the model class for table "entreprise".
 *
 * The followings are the available columns in table 'entreprise':
 * @property integer $idEntreprise
 * @property string $nom
 * @property string $rue
 * @property string $commune
 * @property string $observation
 * @property integer $cp
 * @property string $civilite
 * @property string $gerant
 * @property string $telephone
 * @property string $fax
 * @property string $email
 *
 * The followings are the available model relations:
 * @property Equipe[] $equipes
 */
class Entreprise extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'entreprise';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idEntreprise, cp', 'numerical', 'integerOnly'=>true),
			array('nom, rue, commune, observation, email', 'length', 'max'=>30000),
			array('civilite', 'length', 'max'=>30),
			array('gerant, telephone, fax', 'length', 'max'=>50),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('idEntreprise, nom, rue, commune, observation, cp, civilite, gerant, telephone, fax, email', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'equipes' => array(self::MANY_MANY, 'Equipe', 'equipe_has_bureauetude(idEntreprise, idEquipe)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idEntreprise' => 'Id',
			'nom' => 'Nom',
			'rue' => 'Rue',
			'commune' => 'Commune',
			'observation' => 'Observation',
			'cp' => 'CP',
			'civilite' => 'Civilite',
			'gerant' => 'Gerant',
			'telephone' => 'Telephone',
			'fax' => 'Fax',
			'email' => 'Email',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idEntreprise',$this->idEntreprise);
		$criteria->compare('nom',$this->nom,true);
		$criteria->compare('rue',$this->rue,true);
		$criteria->compare('commune',$this->commune,true);
		$criteria->compare('observation',$this->observation,true);
		$criteria->compare('cp',$this->cp);
		$criteria->compare('civilite',$this->civilite,true);
		$criteria->compare('gerant',$this->gerant,true);
		$criteria->compare('telephone',$this->telephone,true);
		$criteria->compare('fax',$this->fax,true);
		$criteria->compare('email',$this->email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Entreprise the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
